﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("20217141 钟水桥 装饰器模式");
            Phone phone = new ApplePhone();
            Decorator decorator = null;
            //开始贴膜
            decorator = new Sticker(phone);
            decorator.Print();
            Console.WriteLine("--------------");

            //开始增加挂件
            decorator = new Accessories(phone);
            decorator.Print();
            Console.WriteLine("--------------");

            //第二种方式
            Sticker sticker = new Sticker(phone);
            Accessories accessories = new Accessories(sticker);
            accessories.Print();

            Console.ReadKey();
        }
    }
    //手机抽象类，方便不同手机产品和装饰器使用 
    abstract class Phone {
        public abstract void Print();
    }
    class ApplePhone : Phone
    {
        public override void Print()
        {
            Console.WriteLine("开始执行具体的手机对象 苹果手机");
        }
    }
    //装饰器
    abstract class Decorator : Phone {

        private Phone phone;
        public Decorator(Phone phone) { 
            this.phone = phone;
        }
        public override void Print()
        {
            phone.Print();
        }
    }

    //手机外壳
    class Sticker : Decorator
    {
        public Sticker(Phone phone) : base(phone)
        {
        }

        public override void Print()
        {
            base.Print();
            Console.WriteLine("手机上增加了贴膜");
        }
    }
    //手机挂件
    class Accessories : Decorator
    {
        public Accessories(Phone phone) : base(phone)
        {
        }

        public override void Print()
        {
            base.Print();
            Console.WriteLine("手机上增加了外壳");
        }
    }
}
